package com.itnoob.factorybean;

import com.itnoob.factory.PaymentFactory;
import com.itnoob.pay.impl.AliPaymentImpl;
import com.itnoob.pay.impl.WeChatPaymentImpl;
import org.springframework.beans.factory.config.ServiceLocatorFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * 定义一个配置类,使用ServiceLocatorFactoryBean来创建一个动态代理对象,实现支付工厂接口
 * @author zhoujun
 * @date 2025/3/19 21:13
 */
@Configuration
public class PaymentConfig {
     @Bean
     public ServiceLocatorFactoryBean serviceLocatorFactoryBean(){
         ServiceLocatorFactoryBean factoryBean = new ServiceLocatorFactoryBean();
         //设置要代理的接口
         factoryBean.setServiceLocatorInterface(PaymentFactory.class);
         return factoryBean;
     }

     @Bean(name = "wechat")
     @Scope("prototype")
     public WeChatPaymentImpl weChatPayment(){
         return new WeChatPaymentImpl();
     }

     @Bean(name = "ali")
     @Scope("prototype")
    public AliPaymentImpl aliPayment(){
        return new AliPaymentImpl();
    }
}
